package com.example.mymatch.controller;


import com.example.mymatch.model.Checkwork;
import com.example.mymatch.service.ICheckworkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CheckworkController层
 * 编写者：杨滢
 */

@Api(tags = "考勤")
@RestController
public class CheckworkController {
    @Autowired
    private ICheckworkService checkworkService;//对某个业务服务的内容进行定义规范  编写者：杨滢

    @ApiOperation(value = "查询所有考勤信息",notes = "获取考勤信息返回json字符串")
    @RequestMapping("/getStr15")
    public String getCheckwork(){
        return "My checkwork";
    }
    @CrossOrigin
    @ApiOperation(value = "对考勤信息的添加方法")
    @GetMapping("/addCheckwork")
    public int addCheckwork(Checkwork checkwork){
        System.out.println("进入添加考勤信息接口");
        return checkworkService.insertCheckwork(checkwork);
    }

    @GetMapping("getAll15")
    @ApiOperation(value = "对考勤信息的查询方法")
    public List<Checkwork> getAllCheckwork(Checkwork checkwork){
        System.out.println("进入查询方法");

        List<Checkwork> listCheckwork=checkworkService.getAllCheckwork(checkwork);

        return listCheckwork;
    }

    @PutMapping("/editCheckwork")
    @ApiOperation(value = "对考勤信息的修改方法")
    public int EditCheckwork(@RequestBody Checkwork checkwork){
        System.out.println("进入考勤修改方法");
        return checkworkService.updateCheckwork(checkwork);
    }

    @GetMapping("/delCheckwork")
    @ApiOperation(value = "对考勤信息的删除方法")
    public int Delete(int id){
        System.out.println("进入考勤删除方法");
        int returnValue=0;
        if (id!=0){
            Checkwork checkwork=new Checkwork();
            checkwork.setId(id);
            returnValue= checkworkService.deleteCheckwork(checkwork);
        }
        return returnValue;
    }

    @GetMapping("/getOne15")
    @ApiOperation(value = "对单条考勤信息的查询方法")
    public  Checkwork getCheckwork(int id){
        Checkwork checkwork=new Checkwork();
        System.out.println("进入考勤查询方法");
        if (id!=0){
            Checkwork checkwork1=new Checkwork();
            checkwork1.setId(id);
            checkwork=checkworkService.getCheckwork(checkwork1);
            System.out.println("返回的数据集合为："+checkwork.getCheckName());
        }
        return checkwork;
    }
}
